package dto

import (
	"time"
)

// 聊天室相关DTO
type CreateRoomRequest struct {
	Name        string `json:"name" binding:"required,min=1,max=100"`
	Description string `json:"description" binding:"max=500"`
	Type        string `json:"type" binding:"oneof=private group public"`
}

type UpdateRoomRequest struct {
	Name        string `json:"name" binding:"omitempty,min=1,max=100"`
	Description string `json:"description" binding:"omitempty,max=500"`
	Avatar      string `json:"avatar" binding:"omitempty,url"`
}

type RoomResponse struct {
	ID          string           `json:"id"`
	Name        string           `json:"name"`
	Description string           `json:"description"`
	Type        string           `json:"type"`
	Avatar      string           `json:"avatar"`
	CreatorID   string           `json:"creator_id"`
	CreatedAt   time.Time        `json:"created_at"`
	UpdatedAt   time.Time        `json:"updated_at"`
	MemberCount int64            `json:"member_count"`
	LastMessage *MessageResponse `json:"last_message"`
	UnreadCount int64            `json:"unread_count"`
	Creator     *UserResponse    `json:"creator"`
}

type RoomMemberResponse struct {
	ID       string        `json:"id"`
	RoomID   string        `json:"room_id"`
	UserID   string        `json:"user_id"`
	Role     string        `json:"role"`
	JoinedAt time.Time     `json:"joined_at"`
	IsActive bool          `json:"is_active"`
	User     *UserResponse `json:"user"`
}

// 消息相关DTO
type SendMessageRequest struct {
	Content  string `json:"content" binding:"required,min=1"`
	Type     string `json:"type" binding:"oneof=text image file system"`
	FileURL  string `json:"file_url,omitempty"`
	FileName string `json:"file_name,omitempty"`
	FileSize int64  `json:"file_size,omitempty"`
	ReplyTo  string `json:"reply_to,omitempty"`
}

type UpdateMessageRequest struct {
	Content  string `json:"content" binding:"omitempty,min=1"`
	Type     string `json:"type" binding:"omitempty,oneof=text image file system"`
	FileURL  string `json:"file_url,omitempty"`
	FileName string `json:"file_name,omitempty"`
	FileSize int64  `json:"file_size,omitempty"`
}

type MessageResponse struct {
	ID        string           `json:"id"`
	RoomID    string           `json:"room_id"`
	UserID    string           `json:"user_id"`
	Content   string           `json:"content"`
	Type      string           `json:"type"`
	Status    string           `json:"status"`
	ReplyTo   *string          `json:"reply_to"`
	FileURL   *string          `json:"file_url"`
	FileName  *string          `json:"file_name"`
	FileSize  *int64           `json:"file_size"`
	CreatedAt time.Time        `json:"created_at"`
	UpdatedAt time.Time        `json:"updated_at"`
	User      *UserResponse    `json:"user"`
	Reply     *MessageResponse `json:"reply,omitempty"`
	ReadCount int64            `json:"read_count"`
	IsRead    bool             `json:"is_read"`
}

type MessageReadResponse struct {
	ID        string    `json:"id"`
	MessageID string    `json:"message_id"`
	UserID    string    `json:"user_id"`
	ReadAt    time.Time `json:"read_at"`
}

// 好友相关DTO
type SendFriendRequest struct {
	ReceiverID string `json:"receiver_id" binding:"required"`
	Message    string `json:"message" binding:"max=200"`
}

type RespondFriendRequest struct {
	RequestID string `json:"request_id" binding:"required"`
	Status    string `json:"status" binding:"oneof=accepted rejected"`
	Message   string `json:"message" binding:"max=200"`
}

type FriendResponse struct {
	ID        string        `json:"id"`
	UserID    string        `json:"user_id"`
	FriendID  string        `json:"friend_id"`
	Status    string        `json:"status"`
	CreatedAt time.Time     `json:"created_at"`
	UpdatedAt time.Time     `json:"updated_at"`
	Friend    *UserResponse `json:"friend"`
}

type FriendRequestResponse struct {
	ID         string        `json:"id"`
	SenderID   string        `json:"sender_id"`
	ReceiverID string        `json:"receiver_id"`
	Status     string        `json:"status"`
	Message    string        `json:"message"`
	CreatedAt  time.Time     `json:"created_at"`
	UpdatedAt  time.Time     `json:"updated_at"`
	Sender     *UserResponse `json:"sender"`
	Receiver   *UserResponse `json:"receiver"`
}

// 用户状态相关DTO
type UserStatusResponse struct {
	ID       string        `json:"id"`
	UserID   string        `json:"user_id"`
	Status   string        `json:"status"`
	LastSeen time.Time     `json:"last_seen"`
	User     *UserResponse `json:"user"`
}

// 聊天邀请相关DTO
type CreateRoomInviteRequest struct {
	RoomID    string `json:"room_id" binding:"required"`
	InviteeID string `json:"invitee_id" binding:"required"`
}

type RespondRoomInviteRequest struct {
	InviteID string `json:"invite_id" binding:"required"`
	Status   string `json:"status" binding:"oneof=accepted rejected"`
}

type RoomInviteResponse struct {
	ID        string        `json:"id"`
	RoomID    string        `json:"room_id"`
	InviterID string        `json:"inviter_id"`
	InviteeID string        `json:"invitee_id"`
	Status    string        `json:"status"`
	Token     string        `json:"token"`
	ExpiresAt time.Time     `json:"expires_at"`
	CreatedAt time.Time     `json:"created_at"`
	Room      *RoomResponse `json:"room"`
	Inviter   *UserResponse `json:"inviter"`
	Invitee   *UserResponse `json:"invitee"`
}

// 通用响应DTO
type PaginatedResponse struct {
	Data       interface{} `json:"data"`
	Total      int64       `json:"total"`
	Page       int         `json:"page"`
	PageSize   int         `json:"page_size"`
	TotalPages int         `json:"total_pages"`
}

type ChatStatsResponse struct {
	TotalRooms     int64 `json:"total_rooms"`
	TotalMessages  int64 `json:"total_messages"`
	TotalFriends   int64 `json:"total_friends"`
	OnlineUsers    int64 `json:"online_users"`
	UnreadMessages int64 `json:"unread_messages"`
}

// WebSocket消息DTO
type WebSocketMessage struct {
	Type string      `json:"type"`
	Data interface{} `json:"data"`
}

type WebSocketMessageData struct {
	MessageID   string                 `json:"message_id,omitempty"`
	RoomID      string                 `json:"room_id,omitempty"`
	UserID      string                 `json:"user_id,omitempty"`
	Content     string                 `json:"content,omitempty"`
	MessageType string                 `json:"message_type,omitempty"`
	Status      string                 `json:"status,omitempty"`
	Updates     map[string]interface{} `json:"updates,omitempty"`
}

// 搜索相关DTO
type SearchRequest struct {
	Query    string `json:"query" binding:"required,min=1,max=100"`
	Type     string `json:"type" binding:"oneof=users rooms messages"`
	Page     int    `json:"page" binding:"min=1"`
	PageSize int    `json:"page_size" binding:"min=1,max=100"`
}

type SearchResult struct {
	Users    []*UserResponse    `json:"users"`
	Rooms    []*RoomResponse    `json:"rooms"`
	Messages []*MessageResponse `json:"messages"`
	Total    int64              `json:"total"`
	Page     int                `json:"page"`
	PageSize int                `json:"page_size"`
}

// 通知相关DTO
type NotificationResponse struct {
	ID        string      `json:"id"`
	Type      string      `json:"type"`
	Title     string      `json:"title"`
	Message   string      `json:"message"`
	Data      interface{} `json:"data"`
	IsRead    bool        `json:"is_read"`
	CreatedAt time.Time   `json:"created_at"`
}

// 文件上传相关DTO
type FileUploadResponse struct {
	ID       string `json:"id"`
	URL      string `json:"url"`
	Name     string `json:"name"`
	Size     int64  `json:"size"`
	Type     string `json:"type"`
	Uploaded bool   `json:"uploaded"`
}
